package helperF

import (
	"encoding/json"
)

// CopyStructToMap 复制struct到map，非递归
func CopyStructToMap(input interface{}) (map[string]interface{}, error) {
	var result map[string]interface{}
	b, err := json.Marshal(input)
	if err != nil {
		return nil, err
	}
	if err := json.Unmarshal(b, &result); err != nil {
		return nil, err
	}
	return result, nil
}

// CopyMapToStruct 复制map到struct，非递归
func CopyMapToStruct(input map[string]interface{}, dest interface{}) error {
	b, err := json.Marshal(input)
	if err != nil {
		return err
	}
	if err := json.Unmarshal(b, &dest); err != nil {
		return err
	}
	return nil
}
